import random
import string
import json
total=1
def addAChildToitem(item):
	if item.has_key('children'):
		item['children'].append(createAnEndNode())
	else:
		item['children']=[]
		item['children'].append(createAnEndNode())
	return item
def createAnEndNode():
	global total
	total+=1
	inVol=random.uniform(1, 10)
	outVol=random.uniform(1,10)
	while outVol>=inVol:
		outVol=random.uniform(1,10)
	return {
	#'name':string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 9)).replace(" ",""),
	'name':str(++total),
	'in':inVol,
	'out':outVol,	
	}
data={'name':'0'}
for i in xrange(0,random.randint(50,80)):
	addAChildToitem(data)	
for j in xrange(0,len(data['children'])):
	for i in xrange(1,random.randint(15,18)):
		addAChildToitem(data['children'][j])
for j in xrange(0,len(data['children'])):
	for i in xrange(0,len(data['children'][j]['children'])):
		for z in xrange(1,random.randint(15,18)):
			addAChildToitem(data['children'][j]['children'][i])
for j in xrange(0,len(data['children'])):
	for i in xrange(0,len(data['children'][j]['children'])):
		for z in xrange(0,len(data['children'][j]['children'][i]['children'])):
			for k in xrange(1,random.randint(8,10)):
				addAChildToitem(data['children'][j]['children'][i]['children'][z])			
print total
data['totalnodelength']=total
file=open('data.json','w')
file.write(json.dumps(data,sort_keys=True))
file.close()